package hu.bme.aut.consulttime.client.components;

import hu.bme.aut.consulttime.entitydtos.UserDTO;

import com.google.gwt.event.logical.shared.SelectionEvent;
import com.google.gwt.event.logical.shared.SelectionHandler;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.TabPanel;

public class TutorRootPanel extends Composite{

	private UserDTO userData;
	
	private StudentPage studentPage = null;
	private TeamPage teamPage = null;
	private ProjectPage projectPage = null;
	private TutorToDoPage tutorToDoPage = null;
	
	public TutorRootPanel(UserDTO userData) {
		this.userData = userData;
		
		TabPanel tabPanel = new TabPanel();
		initWidget(tabPanel);
		tabPanel.setSize("100%", "100%");
		tabPanel.setAnimationEnabled(true);
		
		studentPage = new StudentPage();
		tabPanel.add(studentPage, "Students", false);
		studentPage.setSize("100%", "100%");
		
		projectPage = new ProjectPage();
		tabPanel.add(projectPage, "Projects", false);
		projectPage.setSize("100%", "100%");
		
		teamPage = new TeamPage();
		tabPanel.add(teamPage, "Teams", false);
		teamPage.setSize("100%", "100%");
		
		tutorToDoPage = new TutorToDoPage();
		tabPanel.add(tutorToDoPage, "To-dos", false);
		tutorToDoPage.setSize("100%", "100%");
		tutorToDoPage.setUserId(this.userData.getUserId());
		
		tabPanel.addSelectionHandler(new SelectionHandler<Integer>() 
		        {
		            public void onSelection(SelectionEvent<Integer> event) 
		            {
		                int tabId = event.getSelectedItem();
		                switch (tabId) {
						case 0:
							StudentPage.loadStudents();
							break;
						case 1:
							ProjectPage.loadProjects();
							break;
						case 2:
							TeamPage.loadTeams();
							break;
						case 3:
							tutorToDoPage.loadProjects();
							break;
						default:
							break;
						}
		            }
		        });
		
		tabPanel.selectTab(0);
				
	}

}
